package frame;

import frame.AdminPanel;
import frame.CommonPanel;

import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.KeyStroke;

public class AdminMainFrame extends JFrame{

    AdminPanel adminPanel;
    TeacherPanel teacherPanel = new TeacherPanel();
    StudentPanel studentPanel = new StudentPanel();
    CoursePanel coursePanel = new CoursePanel();

    CommonPanel currentPanel;

    private Action admin = new AbstractAction("管理员管理", new ImageIcon("images/sale.gif")) {
        public void actionPerformed(ActionEvent e) {
            changePanel(adminPanel);
        }
    };
    private Action teacher = new AbstractAction("教师管理", new ImageIcon("images/sale.gif")) {
        public void actionPerformed(ActionEvent e) {
            changePanel(teacherPanel);
        }
    };
    private Action student = new AbstractAction("学生管理", new ImageIcon("images/sale.gif")) {
        public void actionPerformed(ActionEvent e) {
            changePanel(studentPanel);
        }
    };
    private Action course = new AbstractAction("课程管理", new ImageIcon("images/sale.gif")) {
        public void actionPerformed(ActionEvent e) {
            changePanel(coursePanel);
        }
    };
    public static void main(String[] args) {
        // 创建 AdminMainFrame 实例
        AdminMainFrame frame = new AdminMainFrame();
    }


    public AdminMainFrame() {

        JMenuBar menuBar = new JMenuBar();
        JMenu menu1 = new JMenu("基础设置");
        JMenu menu2 = new JMenu("成绩设置");
        menuBar.add(menu1);
        menuBar.add(menu2);

        menu1.add(admin).setAccelerator(KeyStroke.getKeyStroke('A', InputEvent.CTRL_MASK));
        menu1.add(teacher).setAccelerator(KeyStroke.getKeyStroke('T', InputEvent.CTRL_MASK));
        menu1.add(student).setAccelerator(KeyStroke.getKeyStroke('S', InputEvent.CTRL_MASK));
        menu1.add(course).setAccelerator(KeyStroke.getKeyStroke('C', InputEvent.CTRL_MASK));

//        menu2.add(score).setAccelerator(KeyStroke.getKeyStroke('S', InputEvent.CTRL_MASK));

        //让界面作为第一显示界面
        this.adminPanel = new AdminPanel();
        this.add(adminPanel);
        this.currentPanel = adminPanel;

        this.setJMenuBar(menuBar);
        this.setTitle("学生成绩管理系统");
        //this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       // this.setExtendedState(JFrame.MAXIMIZED_BOTH);
        this.setSize(1100,650);
        this.setLocationRelativeTo(null);
        this.setVisible(true);
    }

    //切换各个界面
    private void changePanel(CommonPanel commonPanel) {
        //移除当前显示的JPanel
        this.remove(currentPanel);
        //添加需要显示的JPanel
        this.add(commonPanel);
        //设置当前的JPanel
        this.currentPanel = commonPanel;
        this.repaint();
        this.setVisible(true);
        //重新读取数据
        commonPanel.setViewDatas();
        //刷新列表
        commonPanel.clear();
    }

}
